package com.renwei.yunlong.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.CompanySelectBean;
import com.renwei.yunlong.view.CircleTextImage;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 业主选择处理企业 Adapter
 * <p>
 * Created by Administrator on 2017/9/12.
 */

public class CompanySelectAdapter extends BaseRecyclerViewAdapter<CompanySelectBean.Rows> {

    private Boolean isShow = true;
    private String companyType;

    public CompanySelectAdapter(Context context, String companyType) {
        super(context);
        this.companyType = companyType;
    }

    public void setPicShow(Boolean isShow) {
        this.isShow = isShow;
    }


    @Override
    public CompanySelectHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_service_select_company, parent, false);
        return new CompanySelectHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {
        CompanySelectHolder holder = (CompanySelectHolder) rholder;
        final CompanySelectBean.Rows rows = getItem(position);
        if (!isShow) {
            holder.ivHead.setVisibility(View.GONE);
        } else {
            holder.ivHead.setText4CircleImage(String.valueOf(rows.getServerName()));
        }
        holder.tvName.setText(rows.getServerName());
        if ("1".equals(companyType)) {
            holder.llNumber.setVisibility(View.VISIBLE);
            holder.tvNumber.setText(rows.getWorkOrderNumber() + "");
        } else {
            holder.llNumber.setVisibility(View.GONE);
        }
        if ("1".equals(rows.getBindFlag())) {
            if ("1".equals(companyType)) {
                holder.ivType.setImageResource(R.mipmap.icon_company_hyfws);
            } else {
                holder.ivType.setImageResource(R.mipmap.icon_company_hyyz);
            }
            holder.ivHead.setTextCircleColor(Color.parseColor("#a9db34"));
        } else if ("2".equals(rows.getBindFlag())) {
            if ("1".equals(companyType)) {
                holder.ivType.setImageResource(R.mipmap.icon_company_zjfws);
            } else {
                holder.ivType.setImageResource(R.mipmap.icon_company_zjyz);
            }
            holder.ivHead.setTextCircleColor(Color.parseColor("#ff7d8c"));
        } else if ("3".equals(rows.getBindFlag())) {
            holder.ivType.setImageResource(R.mipmap.icon_company_zsqy);
            holder.ivHead.setTextCircleColor(Color.parseColor("#5cc9ff"));
        } else {
            holder.ivType.setImageResource(0);
            holder.llNumber.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClickLitener.onItemClick(v, position);
            }
        });
    }


    class CompanySelectHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_head)
        CircleTextImage ivHead;
        @Bind(R.id.tv_number)
        TextView tvNumber;
        @Bind(R.id.ll_number)
        LinearLayout llNumber;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.iv_type)
        ImageView ivType;

        public CompanySelectHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
